const generateEnv = require('./__generateEnv')

const path = require('path')

/**
 * 系统内部核心文件
 * 向外暴露所有配置
 */
class Core {
    constructor() {
        this.cwd = process.cwd()
        this.resolveEnv()
        this.env = process.env.NODE_ENV
        this.pkg = this.resolvePackage()
    }

    //从env读取配置，设置到process
    resolveEnv() {
        const basePath = path.resolve(this.cwd, '.env')
        const localPath = `${basePath}.local`
        generateEnv(localPath) //如果有相同的字段配置，local优先级高
        generateEnv(basePath)
    }

    //获取package配置信息
    resolvePackage() {
        try {
            return require(path.resolve(this.cwd, 'package.json'));
        } catch (e) {
            return {};
        }
    }

}

module.exports = Core